package com.sun.myproject.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.myproject.bean.PageBean;
import com.sun.myproject.dao.UserDao;
import com.sun.myproject.daoimpl.UserDaoImpl;


@WebServlet("/UserListServlet")
public class UserListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public UserListServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			request.setCharacterEncoding("utf-8");
			response.setContentType("text/html;charset=utf-8");
			//1. 获取需要显示的页码数
			int currentPage = 1;
			
			//查询
			String userid1=request.getParameter("userid1");
			System.out.println(userid1);
			if(request.getParameter("currentPage")!=null) {
				
				currentPage =Integer.parseInt( request.getParameter("currentPage"));
			}
			
			//2. 根据指定的页数，去获取该页的数据回来
			//List<User> --- list.jsp
			
			UserDao service = new UserDaoImpl();
			PageBean pageBean= service.findUserByPages(userid1,currentPage);
			request.setAttribute("pageBean", pageBean);
			request.setAttribute("userid1", userid1);
			//3. 跳转界面。
			request.getRequestDispatcher("/Super/User_selectAll.jsp").forward(request, response);
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
